﻿using System;
using System.IO;
using log4net;
using log4net.Config;

namespace Golos.Web
{
    public class LogClass
    {
        static LogClass()
        {
            XmlConfigurator.ConfigureAndWatch(new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, logFileName)));
        }

        public static void WriteDebugEntry(string message)
        {
            if (logger.IsDebugEnabled)
                logger.Debug(string.Format("{0}\r\n", message));
        }

        public static void WriteDebugEntry(string message, params object[] parameters)
        {
            if (logger.IsDebugEnabled)
                logger.Debug(string.Format(message + "\r\n", parameters));
        }

        public static void WriteErrorEntry(string message)
        {
            if (logger.IsErrorEnabled)
                logger.Error(string.Format("{0}\r\n", message));
        }

        public static void WriteErrorEntry(string message, params object[] parameters)
        {
            if (logger.IsErrorEnabled)
                logger.Error(string.Format(message + "\r\n", parameters));
        }

        /*public static void WriteErrorEntry(string message, string errMessage, string errStack)
        {
            if (logger.IsErrorEnabled)
                logger.Error(string.Format(message + "\r\n{0}\r\n{1}", errMessage, errStack));
        }*/

        public static void WriteWarningEntry(string message)
        {
            if (logger.IsWarnEnabled)
                logger.Warn(string.Format("{0}\r\n", message));
        }

        public static void WriteWarningEntry(string message, params object[] parameters)
        {
            if (logger.IsWarnEnabled)
                logger.Warn(string.Format(message + "\r\n", parameters));
        }

        public static void WriteInfoEntry(string message)
        {
            if (logger.IsInfoEnabled)
                logger.Info(string.Format("{0}\r\n", message));
        }

        public static void WriteInfoEntry(string message, params object[] parameters)
        {
            if (logger.IsInfoEnabled)
                logger.Info(string.Format(message + "\r\n", parameters));
        }

        private static readonly log4net.ILog logger = LogManager.GetLogger(typeof(LogClass));
        private const string logFileName = "log.config.xml";


        public void Info(string format, params object[] parameters)
        {
            WriteInfoEntry(format, parameters);
        }

        public void Warn(string format, params object[] parameters)
        {
            WriteWarningEntry(format, parameters);
        }

        public void Error(string format, params object[] parameters)
        {
            WriteErrorEntry(format, parameters);
        }

        public void Debug(string format, params object[] parameters)
        {
            WriteDebugEntry(format, parameters);
        }


    }
}
